﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Collections.Generic;
using DevKnightlie.WPF.AutoForm.FieldDefinitions;
using System.Reflection;

namespace DevKnightlie.WPF.AutoForm.Tests
{
    [TestClass]
    public class ModelObjectFormDefinerTests
    {
        [TestMethod]
        public void CreatesSimpleFieldDefinitionList()
        {
            ModelObjectFormDefiner definer = new ModelObjectFormDefiner();
            TestModelClass model = new TestModelClass();
            definer.ModelObject = model;
            IEnumerable<BaseFieldDefinition> defs = definer.FieldDefinitionList();
            int index = 0;
            PropertyInfo[] props = model.GetType().GetProperties();
            foreach (BaseFieldDefinition fieldDefinition in defs)
            {
                Type T = props[index].PropertyType;
                BaseFieldDefinition def = FieldDefinitionRegistry.Default.Definition(T);
                Assert.AreEqual(fieldDefinition.PropertyName, props[index].Name);
                Assert.IsTrue(def.GetType() == fieldDefinition.GetType());
                index++;
            }
        }
    }
}
